require("../util.js");
require("../component/components.js");
require("../../jsMt/util.js");
var userInfo=JSON.parse(sessionStorage.getItem("userInfo"));
if(!userInfo){
    location.href="/loginIndex"
}
var key="circleId-"+userInfo.id;
// console.log(key)
// var myGoodsList=JSON.parse(sessionStorage.getItem(key));
var vm = new Vue({
    el:"#circleSetup",
    data:{
        isClassify:false,
        // circleId:"",//圈子id
        // uid:"",//用户id
        //isMain:"",//是否是圈主  1 是  0不是
        groupInfo:{},
        products:{},
        pop:{
            question: "您确定要解散圈子？",
            show: false
        },
        data:{
            loginUid:"",
            coverImgSrc:"",
            coverImgWidth:"",
            coverImgHeight:"",
            circleId :""
        },
        imgNum:"1",
        results:{},
        coverImgSrc:"",
        isValidate:"",
        proving:{},
        number:0,
        isScreen:""
        // myGoodsList:myGoodsList

    },
    mounted:function(){
        this.searchObject = this.getQueryStringArgs();
        if(this.searchObject&&this.searchObject.number){
            this.number=this.searchObject&&this.searchObject.number;
            // this.data.circleId=this.searchObject&&this.searchObject.circleId;
            // this.data.loginUid=this.searchObject&&this.searchObject.uid;
        }
        this.data.circleId=this.searchObject&&this.searchObject.circleId;
        this.data.loginUid=this.searchObject&&this.searchObject.uid;
        console.log(this.number)
        //this.isMain=this.searchObject&&this.searchObject.isMain;
        this.getGroupInfo();
    },
    methods:{
        //后退
        getBack: function () {
            //history.go(-1);
            // if(this.square==1){
            //     location.href="/friend/circleSquare";
            // }else{
            //     location.href="/friend?indexs=3";
            // }
            location.href="/friend/circleInfo?circleId="+this.data.circleId+"&uid="+this.data.loginUid;
        },
        bgimg:function(url){
            url = url?url:"";
            return {
                "background-image":'url("'+url+'"),url("")'
            }
        },
        /*获取查询字符对象*/
        getQueryStringArgs: function () {
            //取得查询字符串并去掉开头的问号
            var qs = (location.search.length > 0 ? location.search.substring(1) : ""),
                args = {},
                items = qs.length ? qs.split("&") : [],
                item = null,
                name = null,
                value = null,
                len = items.length;
            for (var i = 0; i < len; i++) {
                item = items[i].split("=");
                name = item[0];
                value = item[1];
                if (name.length) {
                    args[name] = value;
                }
            }
            return args;
        },
        //圈子贴吧信息
        getGroupInfo:function(){
            var that=this;
            var data={
                loginUid:that.data.loginUid,
                circleId:that.data.circleId
            };
            this.ajax({url:"/friend/getGroupInfo",data:data,dataType:"json",method:"post"},function(b){
                if(b.json.code==0&&b.json.data){
                    that.groupInfo=b.json.data;
                    that.products=that.groupInfo.products;
                    if(that.searchObject&&that.searchObject.number){

                    }else{
                        that.number=that.products.length;
                    }

                    console.log(that.number)
                    sessionStorage.setItem(key,JSON.stringify(that.products));
                }else{
                    vm.$refs.prompt.toast("获取圈子信息失败！")
                }
            });
        },
        //获取成员列表
        getGroupMemberInfo:function(){
            var that=this;
            var data={
                loginUid:that.data.loginUid,
                circleId:that.data.circleId
            };
            this.ajax({url:"/friend/getGroupMemberInfo",data:data,dataType:"json",method:"post"},function(b){
                if(b.json.code==0&&b.json.data){
                    that.memberInfo=b.json.data
                }else{
                    vm.$refs.prompt.toast("获取成员失败！")
                }
            });
        },
        //是否解散圈子弹框
        getIsClassify:function(){
            console.log("ddddd")
            this.pop.show=!this.pop.show;
        },
        //解散圈子
        dismissGroup:function(){
            var that=this;
            var data={
                loginUid:that.data.loginUid,
                circleId:that.data.circleId
            };
            console.log(data);
            that.getIsClassify();
            this.ajax({url:"/friend/dismissGroup",data:data,dataType:"json",method:"post"},function(b){
                if(b.json.code==0){
                    location.href="/friend?indexs=3";
                }else{
                    vm.$refs.prompt.toast("解散圈子失败！");
                }
            });
        },
        getChange:function(){
            var that=this;
            that.data.coverImgSrc=$("#fileinput").get(0).files[0];
            lrz(that.data.coverImgSrc, function (results) {
                // 你需要的数据都在这里，可以以字符串的形式传送base64给服务端转存为图片。
                console.log(results);
                that.results=results;
                demo_report(results.base64);
            });
            var formData = new FormData();
            formData.append("loginUid", that.data.loginUid);
            formData.append("coverImgWidth ",that.data.coverImgWidth);
            formData.append("coverImgHeight ", that.data.coverImgHeight);
            formData.append("circleId", that.data.circleId);
            formData.append("coverImgSrc",that.data.coverImgSrc);
            //console.log(that.data)
            $.ajax({
                url:host+'/v1/friend/updateGroupCoverImgSrc',
                type:'POST',
                data:formData,
                dataType:'json',
                async: false,
                cache: false,
                contentType: false, //不设置内容类型
                processData: false, //不处理数据
                success:function(data){
                    console.log(data);
                    // alert(data.msg);
                    if(data.code==0){
                        that.imgNum=2;
                    }
                },
                error:function(){
                    vm.$refs.prompt.toast("修改封面失败！")
                }
            });
        },
        //成员验证
        getSelect:function(){
            var that=this;
            var data = [{ "id": "0", "value": "任何人可加入" }, { "id": "1", "value": "需经过圈主同意" }];
            var bankSelect = new IosSelect(1,
                [data],
                {
                    container: '.provingMode',
                    itemHeight: 30,
                    itemShowCount: 3,
                    callback: function (selectOneObj) {
                        console.log(that.selectOneObj)
                        var data1={
                            loginUid:that.data.loginUid,
                            circleId:that.data.circleId,
                            isValidate:selectOneObj.id
                        };
                        that.ajax({url:"/friend/updateGroupValidate",data:data1,dataType:"json",method:"post"},function(b){
                            if(b.json.code==0){
                                that.proving=selectOneObj;
                                console.log(that.proving)
                            }else{
                                vm.$refs.prompt.toast("修改成员验证失败！")
                            }
                        });
                    }
                });
        },
        getIsScreen:function(num){
            this.isScreen=num;
        },
        //购买展位
        buyBooth:function(){
            var that=this;
            if(that.number>=5){
                that.getIsScreen();
                vm.$refs.prompt.toast("最多可以购买5个展位");
            }else{
                var data={
                    loginUid:that.data.loginUid,
                    circleId:that.data.circleId
                };
                this.ajax({url:"/cityAd/buyBooth",data:data,dataType:"json",method:"post"},function(b){
                    if(b.json.code==0){
                        that.number++;
                        console.log(that.number)
                        that.getIsScreen();
                        vm.$refs.prompt.toast("购买成功！");
                    }else{
                        that.getIsScreen();
                        vm.$refs.prompt.toast(b.json.msg)
                    }
                });
            }
        },
        getGoods:function(item){
            // sessionStorage.setItem(categoryName,JSON.stringify(this.categoryName));
            // sessionStorage.setItem(cityName,JSON.stringify(this.cityName));
            // sessionStorage.setItem(data,JSON.stringify(this.datalist));
            //circleSetup?circleId=43671d1959554fe292856576c89463bd&uid=7&isMain=1
            console.log(item)
            if(item&&item!=1){
                location.href="/myGoods?type=2&uid="+this.data.loginUid+"&productId="+item.productId+"&number="+this.number+"&circleId="+this.data.circleId+"&isMain="+this.groupInfo.isMain;
            }else{
                location.href="/myGoods?type=2&uid="+this.data.loginUid+"&number="+this.number+"&circleId="+this.data.circleId+"&isMain="+this.groupInfo.isMain;
            }
        },
        getNext:function(type){
            var path;
            if(type==1){
                path="/friend/circleMember?circleId="+this.data.circleId+"&uid="+this.data.loginUid+"&isMain="+this.groupInfo.isMain;
            }else if(type==2){
                path="/friend/abstractEdit?circleId="+this.data.circleId+"&uid="+this.data.loginUid;
            }else if(type==3){
                path="/friend/changeChannel?type=1&circleId="+this.data.circleId+"&uid="+this.data.loginUid+"&categoryId="+this.groupInfo.categoryId;
            }else if(type==4){
                path="/friend/modifyNumber?circleId="+this.data.circleId+"&uid="+this.data.loginUid;
            }
            location.href=path;
        }
    }
});
function demo_report(src) {
    var img = new Image();
    img.onload=function(){
        vm.data.coverImgWidth = img.width;
        vm.data.coverImgHeight = img.height;

    };
    $(".circleSetup-cover").append(img);
    img.src = src;
}